package com.minimalist.lindi.controller;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.purchaseapplication.LindiPurchaseApplicationApprovalVO;
import com.minimalist.common.entity.lindi.vo.purchaseapplication.LindiPurchaseApplicationQueryVO;
import com.minimalist.common.entity.lindi.vo.purchaseapplication.LindiPurchaseApplicationVO;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import com.minimalist.lindi.manager.LindiPurchaseApplicationManager;
import com.minimalist.lindi.service.LindiPurchaseApplicationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 林地指标交易平台_指标购买申请控制器
 *
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_指标购买申请管理")
@RequestMapping("/lindi/purchaseApplication")
public class LindiPurchaseApplicationController{

    @Autowired
    private LindiPurchaseApplicationService service;

    @Autowired
    private LindiPurchaseApplicationManager lindiPurchaseApplicationManager;

    @PostMapping("/addPurchaseApplication")
    @Operation(summary = "添加指标购买申请")
    public R<?> addPurchaseApplication(
            @RequestBody @Validated(Add.class)
            LindiPurchaseApplicationVO purchaseApplicationVO){
        service.addPurchaseApplication(purchaseApplicationVO);
        return R.ok();
    }

    @DeleteMapping("/deletePurchaseApplicationByPurchaseApplicationId")
    @Operation(summary = "删除指标购买申请 -> 根据购买申请ID删除")
    public R<?> deletePurchaseApplicationByPurchaseApplicationId(
            @RequestParam("purchaseApplicationId")
            @NotNull(message = "购买申请ID不能为空")
            @Parameter(name = "purchaseApplicationId", required = true, description = "购买申请ID")
            Long purchaseApplicationId){
        service.deletePurchaseApplicationByPurchaseApplicationId(purchaseApplicationId);
        return R.ok();
    }

    @PutMapping("/updatePurchaseApplicationByPurchaseApplicationId")
    @Operation(summary = "修改指标购买申请")
    public R<?> updatePurchaseApplicationByPurchaseApplicationId(
            @RequestBody @Validated(Update.class)
            LindiPurchaseApplicationVO purchaseApplicationVO){
        service.updatePurchaseApplicationByPurchaseApplicationId(purchaseApplicationVO);
        return R.ok();
    }

    @GetMapping("/getPagePurchaseApplicationList")
    @Operation(summary = "查询指标购买申请列表(分页)")
    public R<PageResp<LindiPurchaseApplicationVO>> getPagePurchaseApplicationList(
            LindiPurchaseApplicationQueryVO queryVO){
        return R.ok(service.getPagePurchaseApplicationList(queryVO));
    }

    @GetMapping("/getPurchaseApplicationByPurchaseApplicationId/{purchaseApplicationId}")
    @Operation(summary = "根据购买申请ID查询指标购买申请")
    public R<LindiPurchaseApplicationVO> getPurchaseApplicationByPurchaseApplicationId(
            @PathVariable(value = "purchaseApplicationId")
            @NotNull(message = "购买申请ID不能为空")
            @Parameter(name = "purchaseApplicationId", description = "购买申请ID", required = true)
            Long purchaseApplicationId){
        return R.ok(service.getPurchaseApplicationByPurchaseApplicationId(purchaseApplicationId));
    }

    @PostMapping("/approvePurchaseApplication")
    @Operation(summary = "审批指标购买申请")
    public R<?> approvePurchaseApplication(
            @Validated @RequestBody LindiPurchaseApplicationApprovalVO approvalVO){
        lindiPurchaseApplicationManager.approvePurchaseApplication(approvalVO);
        return R.ok();
    }



    @PostMapping("/deletePurchaseApplicationFileByFileId")
    @Operation(summary = "删除指标购买申请文件 -> 根据文件ID删除")
    public R<?> deletePurchaseApplicationFileByFileId(
            @RequestParam("fileId")
            @NotNull(message = "文件ID不能为空")
            @Parameter(name = "fileId", description = "文件ID", required = true)
            Long fileId){
        service.deletePurchaseApplicationFileByFileId(fileId);
        return R.ok();
    }
}